package com.hspedu.map_;

import java.util.Properties;

/**
 * @Author Stringzhua
 * @Date 2024/3/13 16:39
 * description:Map的实现接口类Properties
 */
@SuppressWarnings("all")
public class Properties_ {
    public static void main(String[] args) {
        //1.Properties 继承了Hashtable
        //2.可以通过键值对k-v来存放数据,当然key和value不能为null
        //增加
        Properties properties = new Properties();
        properties.put("john", 100);//k-v
//        properties.put(null,"abc");//抛出空指针异常 NullPointerException
//        properties.put("abc",null);
        properties.put("john", 100);
        properties.put("lucy", 100);
        properties.put("lic", 100);
        properties.put("lic", 88);//如果存在相同的key,value被替换

        System.out.println("properties = " + properties);

        //查询
        //通过key获取对应的值
        System.out.println(properties.get("lic"));//88
        System.out.println(properties.getProperty("john"));
        //删除元素
        properties.remove("lic");
        System.out.println("properties = " + properties);

        //修改[替换]
        properties.put("john","约翰");
        System.out.println("properties = " + properties);
    }
}
